package classtest;

import classtest_domain.Book;
import classtest_domain.Rectangle;

/**
 * @version 1.0
 * @auther liquan
 * @date 2025/3/20 0:15
 * @description
 */
public class Demo1 {
    public static void main(String[] args) {
        Book[] books = new Book[4];

        // 遍历数组存入书的对象
        books[0] = new Book(5422,"Romance of the Three Kingdoms", "Luo Guanzhong", 45.99, 168450,15426722);
        books[1] = new Book(1455,"Pilgrimage to the West", "Wu Chengen", 39.99, 205640,87468495);
        books[2] = new Book(4518,"Outlaws of the Marsh", "Shi Naian", 55.99, 108450,78464516);
        books[3] = new Book(7458,"A Dream of Red Mansions", "Cao Xueqing", 49.99, 180452,84565425);

        // 遍历显示Book信息
        System.out.println("Books before sorting:");
        for (Book book : books) {
            System.out.println(book.getinfo());
        }

        // 按照面积从小到大排序
        for (int i = 0; i < books.length - 1; i++) {
            for (int j = 0; j < books.length - 1; j++) {
                // 比较相邻元素，书本对象的销量
                if (books[j].getSales() < books[j + 1].getSales()){
                    Book temp = books[j];
                    books[j] = books[j + 1];
                    books[j + 1] = temp;
                }
            }
        }

        System.out.println("=============================================================================================");
        // 再次遍历
        for (Book book : books) {
            System.out.println(book.getinfo());
        }
    }
}
